package com.group.project.hrms.service.impl;

import com.group.project.hrms.entity.SalaryBaseAllowanceReward;
import com.group.project.hrms.mapper.SalaryBaseAllowanceRewardMapper;
import com.group.project.hrms.service.ISalaryBaseAllowanceRewardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class SalaryBaseAllowanceRewardService implements ISalaryBaseAllowanceRewardService {

    @Autowired
    private SalaryBaseAllowanceRewardMapper salaryBaseAllowanceRewardMapper;


    @Override
    public int insertSalaryBaseAllowanceReward(SalaryBaseAllowanceReward baseAllowanceReward) {
        return salaryBaseAllowanceRewardMapper.insert(baseAllowanceReward);
    }

    @Override
    public int deleteSalaryBaseAllowanceReward(SalaryBaseAllowanceReward baseAllowanceReward) {
        return salaryBaseAllowanceRewardMapper.deleteByPrimaryKey(baseAllowanceReward);
    }

    @Override
    public int updateSalaryBaseAllowanceReward(SalaryBaseAllowanceReward baseAllowanceReward) {
        return salaryBaseAllowanceRewardMapper.updateByPrimaryKey(baseAllowanceReward);
    }

    @Override
    public SalaryBaseAllowanceReward selectOneSalaryBaseAllowanceReward(SalaryBaseAllowanceReward baseAllowanceReward) {
        return null;
    }

    @Override
    public SalaryBaseAllowanceReward selectOneSalaryBaseAllowanceRewardByFileMonthAndContactID(String fileMonth, String cid) {
        Example example = new Example(SalaryBaseAllowanceReward.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("monthFlag", "%" + fileMonth + "%");
        criteria.andEqualTo("contactId", cid);
        return salaryBaseAllowanceRewardMapper.selectOneByExample(example);
    }

    @Override
    public List<SalaryBaseAllowanceReward> selectSalaryBaseAllowanceRewardByMonth(String month) { //month: 2022-06
        Example example = new Example(SalaryBaseAllowanceReward.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("monthFlag", "%" + month + "%");
        return salaryBaseAllowanceRewardMapper.selectByExample(example);
    }

    @Override
    public List<SalaryBaseAllowanceReward> selectAllSalaryBaseAllowanceReward() {
        return salaryBaseAllowanceRewardMapper.selectAll();
    }
}
